import requests
import logging
class Test():
    dl=""
    def setup_method(self):
        print("初始化环境，开始执行用例")
    def teardoen_method(self):
        print("优化环境，用例执行结束")
    #登录
    def test_denglu(self):
        try:
            url="http://10.59.9.21/api/user/login"
            body={"username":"admin","password":"8i4De25KlVQVwqTDgTNGqw=="}
            headers={"content-type":"application/json"}
            r=requests.post(url=url,json=body,headers=headers)
            print(r.json())
            assert r.status_code==200
            assert '登录成功' in r.text
            assert r.json()["msg"]=='登录成功'
        except Exception as e:
            logging.info(e)
        Test.dl=r.json()["token"]
    #新增地区接口
    def test_xinzeng(self):
        try:
            url="http://10.59.9.21/api/area/add"
            body={"atype":2,"name":"海南1","sort":"111"}
            headers={"uid":"1","token":Test.dl}
            r=requests.post(url=url,json=body,headers=headers)
            print(r.json())
            assert r.status_code == 200
            assert '0' in r.text
            assert r.json()["msg"]== '该地区名已存在'
        except Exception as e:
            logging.info(e)
    #查询地区接口
    def test_chaxun(self):
        try:
            url="http://10.59.9.21/api/area/get"
            body={"wheres":"name like \"%海南1%\" ","sorts":"atype asc,sort asc","pageIndex":1,"pageSize":10}
            headers={"uid":"1","token":Test.dl}
            r=requests.post(url=url,json=body,headers=headers)
            print(r.json())
            assert r.status_code == 200
            assert '登录成功' in r.text
            assert r.json()["data"]["list"]["name"]== '海南1'
        except Exception as e:
            logging.info(e)